{extend name="lib/common_list" /}
{block name="title"}新增成员{/block}
{block name="css"}{/block}
{block name="javascript"}
    <script type="text/javascript">
        function initRUAddTable() {
            //先销毁表格
            $('#roleuseradd_tb').bootstrapTable('destroy');
            //初始化表格,动态从服务器加载数据
            $("#roleuseradd_tb").bootstrapTable({
                method: "Post",  //使用get请求到服务器获取数据
                url: "{:url('manager/getuserlist')}", //获取数据的Servlet地址
                striped: true,  //表格显示条纹
                pagination: true, //启动分页
                pageSize: 20,  //每页显示的记录数
                pageNumber: 1, //当前第几页
                pageList: [20, 50],  //记录数可选列表
                search: false,  //是否启用查询
                sidePagination: "server", //表示服务端请求
                queryParamsType: "limit",
                contentType: "application/x-www-form-urlencoded",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        roleid : {$roleid},
                        limit: params.limit,
                        offset: params.offset,
                        keyword: $("#keyword").val()
                    };
                    return param;
                },
                onLoadSuccess: function () {  //加载成功时执行

                },
                onLoadError: function () {  //加载失败时执行
                    layer.msg("加载数据失败", { time: 1500, icon: 2 });
                },
                rowStyle: function (row, index) {
                    var strclass = "";
                    if (row.IsDisable) {
                        strclass = 'danger';
                    }
                    else {
                        return {};
                    }
                    return { classes: strclass }
                }
            });
        }

        $(document).ready(function () {
            //调用函数，初始化表格
            initRUAddTable();
            //当点击查询按钮的时候执行
            $("#search").bind("click", initRUAddTable);
            $("#cancel").bind("click", function () {
                parent.layer.close(parent.layer_roleuseradd_index);
            });
            $("#ok").bind("click", Save);
        });
        
        function Save() {
            var selectRows = $("#roleuseradd_tb").bootstrapTable("getSelections");
            var _userIds = Array();
            for(var i=0;i<selectRows.length;i++){
                _userIds.push(selectRows[i].id);
            }
            var load_index = layer.load(0, { shade: false });
            $.ajax({
                type: "post",
                url: "{:url('role/saveuserrole')}?t=" + new Date(),
                data: { roleid: {$roleid}, userIds: _userIds.join(',') },
                dataType: "json",
                success: function (result) {
                    layer.close(load_index);
                    if (result.code == 0) {
                        layer.alert('保存成功！', function () {
                            if (typeof (parent.initRoleUserTable) == "function")
                                parent.initRoleUserTable();
                            parent.layer.close(parent.layer_roleuseradd_index)
                        });
                    } else {
                        layer.alert(result.msg);
                    }
                },
                error:function(xhr,textStatus){
                    layer.close(load_index);
                    layer.alert('服务器繁忙！');
                }
            });
        }
    </script>
{/block}
{block name="content"}
   <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>新增成员</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-2 m-b-xs">                           
                            </div>
                            <div class="col-sm-2 col-sm-offset-3">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <input type="text" placeholder="请输入关键词" class="input-sm form-control" id="keyword" name="keyword">
                                        <button type="button" class="btn btn-sm btn-primary" id="search">搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <table data-toggle="table" id="roleuseradd_tb" data-pagination="true">
                            <thead>
                                <tr>
                                    <th data-checkbox="true"></th>
                                    <th data-field="real_name" data-align="center">成员名称</th>                               
                                </tr>
                            </thead>
                        </table>
                        <div class="form-group">
                            <div class="col-sm-12" style="text-align:center;">
                                <button class="btn btn-primary" id="ok" type="button">提交</button>
                                <button class="btn btn-white" id="cancel" type="button">取消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>        
{/block}
